﻿<%@ Page Title="" Language="C#" MasterPageFile="~/RootCustomer.Master" AutoEventWireup="true"
    CodeBehind="Register.aspx.cs" Inherits="Project_Udrinkwater.Customer.Register" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="server">
    <dx:ASPxRoundPanel ID="RPN_Promotion" runat="server" Width="100%" 
        HeaderText="ลงทะเบียน">
        <HeaderStyle Font-Size="Medium" HorizontalAlign="Left" />
        <PanelCollection>
<dx:PanelContent runat="server" SupportsDisabledAttribute="True">
    <script type="text/javascript">
        function OnNameValidation(s, e) {
            var objConnection = new ActiveXObject("adodb.connection");
            var strConn = "driver={sql server};server=PEAW;database=DB_Udrink;uid=sa;password=12345678";
            objConnection.Open(strConn);
            var rs = new ActiveXObject("ADODB.Recordset");
            var strQuery = "SELECT * FROM TB_Customer WHERE Customer_ID = '" + e.value + "'";
            rs.Open(strQuery, objConnection);
            rs.MoveFirst
            while (!rs.eof) {
                document.write(rs.fields(1));
                rs.movenext;
            }
            var name = e.value;
            if (name == rs(0))
                return;
            if (name != rs(1))
                e.isValid = false;
        }
    </script>
    <table style="width: 100%;">
        <tr>
            <td style="width: 291px; text-align: right;">
                ชื่อผู้ใช้ :
            </td>
            <td style="width: 217px">
                <dx:ASPxTextBox ID="txtUser" runat="server" Width="170px" ClientInstanceName="Name">
                    <ValidationSettings ValidationGroup="RegisterUserValidationGroup">
                        <RequiredField ErrorText="กรุณากรอกข้อมูล" IsRequired="true" />
                    </ValidationSettings>
                </dx:ASPxTextBox>
            </td>
            <td style="width: 533px">
                &nbsp;</td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                &nbsp;</td>
            <td style="width: 217px">
                <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" 
                    Text="ตรวจสอบ" />
                <asp:Label ID="Label1" runat="server"></asp:Label>
            </td>
            <td style="width: 533px">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                รหัสผ่าน :
            </td>
            <td style="width: 217px">
                <dx:ASPxTextBox ID="txtPassword" runat="server" ClientInstanceName="Password" Password="true"
                    Width="170px">
                    <ValidationSettings ValidationGroup="RegisterUserValidationGroup">
                        <RequiredField ErrorText="กรุณากรอกข้อมูล" IsRequired="true" />
                    </ValidationSettings>
                </dx:ASPxTextBox>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                คำนำหน้า :
            </td>
            <td style="width: 217px">
                <asp:DropDownList ID="DropDownList1" runat="server">
                    <asp:ListItem>นาย</asp:ListItem>
                    <asp:ListItem>นาง</asp:ListItem>
                    <asp:ListItem>นางสาว</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="height: 25px; width: 291px; text-align: right;">
                ชื่อ :
            </td>
            <td style="height: 25px; width: 217px">
                <dx:ASPxTextBox ID="txtFName" runat="server" Width="170px">
                    <ValidationSettings ValidationGroup="RegisterUserValidationGroup">
                        <RequiredField ErrorText="กรุณากรอกข้อมูล" IsRequired="true" />
                    </ValidationSettings>
                </dx:ASPxTextBox>
            </td>
            <td style="height: 25px; width: 533px">
                &nbsp;
            </td>
            <td style="height: 25px">
            </td>
        </tr>
        <tr>
            <td style="height: 23px; width: 291px; text-align: right;">
                นามสกุล :
            </td>
            <td style="height: 23px; width: 217px">
                <dx:ASPxTextBox ID="txtLname" runat="server" Width="170px">
                    <ValidationSettings ValidationGroup="RegisterUserValidationGroup">
                        <RequiredField ErrorText="กรุณากรอกข้อมูล" IsRequired="true" />
                    </ValidationSettings>
                </dx:ASPxTextBox>
            </td>
            <td style="height: 23px; width: 533px">
                &nbsp;
            </td>
            <td style="height: 23px">
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                บ้านเลขที่ / หมู :
            </td>
            <td style="width: 217px">
                <dx:ASPxTextBox ID="txtAdress" runat="server" Width="170px">
                    <ValidationSettings ValidationGroup="RegisterUserValidationGroup">
                        <RequiredField ErrorText="กรุณากรอกข้อมูล" IsRequired="true" />
                    </ValidationSettings>
                </dx:ASPxTextBox>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="height: 25px; width: 291px; text-align: right;">
                จังหวัด :
            </td>
            <td style="height: 25px; width: 217px">
                <asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True" DataSourceID="SqlDataProvince"
                    DataTextField="PROVINCE_NAME" DataValueField="PROVINCE_ID" 
                    OnSelectedIndexChanged="ddlProvince_SelectedIndexChanged" Width="170px">
                </asp:DropDownList>
                &nbsp;
            </td>
            <td style="height: 25px; width: 533px">
                <asp:SqlDataSource ID="SqlDataProvince" runat="server" ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>"
                    
                    SelectCommand="SELECT [PROVINCE_ID], [PROVINCE_NAME] FROM [TB_Province] ORDER BY [PROVINCE_NAME]"></asp:SqlDataSource>
            </td>
            <td style="height: 25px">
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                อำเภอ :
            </td>
            <td style="width: 217px">
                <asp:DropDownList ID="ddlAmphur" runat="server" AutoPostBack="True" DataSourceID="SqlDataAmphur"
                    DataTextField="AMPHUR_NAME" DataValueField="AMPHUR_ID" 
                    OnSelectedIndexChanged="ddlAmphur_SelectedIndexChanged" Width="170px">
                </asp:DropDownList>
            </td>
            <td style="width: 533px">
                <asp:SqlDataSource ID="SqlDataAmphur" runat="server" ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>"
                    
                    SelectCommand="SELECT [AMPHUR_ID], [AMPHUR_NAME], [PROVINCE_ID] FROM [TB_Amphur] WHERE ([PROVINCE_ID] = @PROVINCE_ID) ORDER BY [AMPHUR_NAME]">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddlProvince" Name="PROVINCE_ID" PropertyName="SelectedValue"
                            Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                ตำบล :
            </td>
            <td style="width: 217px">
                <asp:DropDownList ID="ddlDistrict" runat="server" AutoPostBack="True" DataSourceID="SqlDataDistrict"
                    DataTextField="DISTRICT_NAME" DataValueField="DISTRICT_ID" Width="170px">
                </asp:DropDownList>
            </td>
            <td style="width: 533px">
                <asp:SqlDataSource ID="SqlDataDistrict" runat="server" ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>"
                    
                    SelectCommand="SELECT DISTRICT_ID, DISTRICT_NAME, AMPHUR_ID, PROVINCE_ID FROM TB_District WHERE (PROVINCE_ID = @PROVINCE_ID) AND (AMPHUR_ID = @AMPHUR_ID) ORDER BY DISTRICT_NAME">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddlProvince" Name="PROVINCE_ID" PropertyName="SelectedValue"
                            Type="Int32" />
                        <asp:ControlParameter ControlID="ddlAmphur" Name="AMPHUR_ID" PropertyName="SelectedValue"
                            Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="height: 25px; width: 291px; text-align: right;">
                รหัสไปรษณีย์ :
            </td>
            <td style="height: 25px; width: 217px">
                <dx:ASPxTextBox ID="txtPostcode" runat="server" Width="170px">
                    <ValidationSettings ValidationGroup="RegisterUserValidationGroup">
                        <RequiredField ErrorText="กรุณากรอกข้อมูล" IsRequired="true" />
                    </ValidationSettings>
                </dx:ASPxTextBox>
            </td>
            <td style="height: 25px; width: 533px">
                &nbsp;
            </td>
            <td style="height: 25px">
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                เบอร์โทรศัพท์ :
            </td>
            <td style="width: 217px">
                <dx:ASPxTextBox ID="txtPhone" runat="server" Width="170px">
                </dx:ASPxTextBox>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                เบอร์ Fax :
            </td>
            <td style="width: 217px">
                <dx:ASPxTextBox ID="txtFax" runat="server" Width="170px">
                </dx:ASPxTextBox>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px; text-align: right;">
                E-Mail :
            </td>
            <td style="width: 217px">
                <dx:ASPxTextBox ID="txtE_mail" runat="server" Width="170px">
                </dx:ASPxTextBox>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px">
                &nbsp;
            </td>
            <td style="width: 217px">
                <dx:ASPxButton ID="ASPxButton1" runat="server" OnClick="ASPxButton1_Click" Text="ลงทะเบียน"
                    ValidationGroup="RegisterUserValidationGroup" Theme="Office2003Blue">
                </dx:ASPxButton>
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
        <tr>
            <td style="width: 291px">
                &nbsp;
            </td>
            <td style="width: 217px">
                &nbsp;
            </td>
            <td style="width: 533px">
                &nbsp;
            </td>
            <td>
                &nbsp;
            </td>
        </tr>
    </table>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DB_UdrinkConnectionString %>"
        InsertCommand="INSERT INTO TB_Customer(Customer_ID, E_mail, Prefix, Firstname, Lastname, Adress, SubDistrict, District, Province, Postcode, Phone, Fax) VALUES (@Customer_ID, @E_mail, @Prefix, @Firstname, @Lastname, @Adress, @SubDistrict, @District, @Province, @Postcode, @Phone, @Fax)"
        SelectCommand="SELECT [Customer_ID] FROM [TB_Customer]
WHERE Customer_ID = @Customer_ID">
        <InsertParameters>
            <asp:Parameter Name="Customer_ID" />
            <asp:Parameter Name="E_mail" />
            <asp:Parameter Name="Prefix" />
            <asp:Parameter Name="Firstname" />
            <asp:Parameter Name="Lastname" />
            <asp:Parameter Name="Adress" />
            <asp:Parameter Name="SubDistrict" />
            <asp:Parameter Name="District" />
            <asp:Parameter Name="Province" />
            <asp:Parameter Name="Postcode" />
            <asp:Parameter Name="Phone" />
            <asp:Parameter Name="Fax" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="txtUser" Name="Customer_ID" PropertyName="Text" />
        </SelectParameters>
    </asp:SqlDataSource>
    </dx:PanelContent>
</PanelCollection>
    </dx:ASPxRoundPanel>
</asp:Content>
